class Car < ActiveRecord::Base
  has_many :driving_lessons

  validates :registration_number, :presence => true
  validates :manufacturer, :presence => true
  validates :model, :presence => true
  validates :engine_type, :presence => true
  validates :gearbox_type, :presence => true

  validates :engine_type, :inclusion => { :in => 1..2}
  validates :gearbox_type, :inclusion => { :in => 1..2}
  validates :registration_number, :format => { :with => /^\d{3} [A-Z]{3}$/ }

  def display
    [[manufacturer, model].compact.join(' '), registration_number].compact.join(', ')
  end
end
